<template>
    <div class="content">
        <div class="mainContent" v-if="status">
            <div class="leftPart">
                <div class="for_img1">
                    <div class="position">
                        <div class="pos_item_left">申请人 :</div>
                        <div class="pos_item_right">{{detail.name}}</div>
                    </div>
                </div>
                <div class="theLine1"></div>
                <div class="for_img2">
                    <div class="position">
                        <div class="pos_item_left">工号 :</div>
                        <div class="pos_item_right">{{detail.jobNumber}}</div>
                    </div>
                </div>
                <div class="theLine2"></div>

                <div class="for_img3">
                    <div class="position">
                        <div class="pos_item_left">所属园区 :</div>
                        <div class="pos_item_right">{{detail.garden}}</div>
                    </div>
                </div>
            </div>
            <div class="rightPart">
                <div class="for_img4">
                    <div class="position">
                        <div class="pos_item_left">通行区域 :</div>
                        <div class="pos_item_right">{{detail.area}}</div>
                    </div>
                </div>
                <div class="theLine1"></div>
                <div class="for_img5">
                    <div class="position">
                        <div class="pos_item_left">通行次数 :</div>
                        <div class="pos_item_right">{{detail.goCount}}</div>
                    </div>
                </div>
                <div class="theLine2" style="margin-top: 22px"></div>
                <div class="for_img6">
                    <div class="position">
                        <div class="pos_item_left">通行时间 :</div>
                        <div class="pos_item_right">{{detail.dateDay}}</div>
                    </div>
                </div>
            </div>
            <div class="forBut">
                <div class="subButton" @click="agree"><span class="subcontent">同意</span></div>
                <div class="rejButton" @click="reject"><span class="subcontent">拒绝</span></div>
            </div>
        </div>
        <div class="mainContent" v-if="!status">
             <span class="noRight">无访问权限!</span>
        </div>
    </div>
</template>

<script>
    import baseUrl from "../../config/baseUrl";

    export default {
        data() {
            return {
                code: '',
                detail: {},
                status:true,
            };
        },
        created() {
            if(!sessionStorage.getItem("UseingCode")){
                if (!this.getQueryVariable("code")) {
                    this.$api.redirectUrl().then((res) => {
                        var url=window.location.protocol+"//"+window.location.hostname+":"+window.location.port+window.location.pathname+window.location.hash;
                        url = encodeURIComponent(url);
                        window.location.href = res.url+url
                        //  window.location.href = res.url+"http://10.190.47.154:8080/%23%2Fhcg"
                    }).catch((err) => {
                        console.log(err)
                    })
                    // window.location.href = config.hostUrl + 'redirectToAuth';
                } else {
                    sessionStorage.setItem("UseingCode",this.getQueryVariable("code"))
                    let Params = {
                        code: this.getQueryVariable("code"),
                    }
                    this.$api.HiPassLogin(Params).then((res) => {
                        this.JobNum=res.userInfo.loginName;
                        sessionStorage.setItem("jobNum",res.userInfo.loginName);
                        this.getDetail();
                    }).catch((err) => {
                        console.log(err)
                    })

                }
            }

        },
        methods: {
            agree() {
                let _this =this;
                let ids=[];
                ids[0]=_this.getQueryVariable("hipass_id")*1;
                this.$api.agree({ids:ids, auditor: sessionStorage.getItem("ids")}).then((res) => {
                    sessionStorage.setItem('ids',_this.detail.auditor);
                    this.$router.push({ name: 'applyList', params: { id: _this.detail.auditor }})
                }).catch((err) => {
                    console.log(err)
                })
            },
            reject() {
                let _this =this;
                let ids=[];
                ids[0]=_this.getQueryVariable("hipass_id")*1;
                this.$api.reject({ids:ids, auditor: sessionStorage.getItem("ids")}).then((res) => {
                    sessionStorage.setItem('ids',_this.detail.auditor);
                    this.$router.push({ name: 'applyList', params: { id: sessionStorage.getItem("ids") }})
                }).catch((err) => {
                    console.log(err)
                })
            },
            getQueryVariable(variable) {
                var query = window.location.href.substring(1);
                var vars = query.split("&");
                for (var i = 0; i < vars.length; i++) {
                    var pair = vars[i].split("=");
                    if (pair[0] == variable) {
                        return pair[1];
                    }
                }

                if (window.location.href.split("?")[1]) {
                    if (variable == window.location.href.split("?")[1].split("&")[0].split("=")[0]) {
                        return window.location.href.split("?")[1].split("&")[0].split("=")[1]
                    }
                }
                return (false);
            },
            getDetail() {
                const usedata = {id: this.getQueryVariable("hipass_id")*1}
                this.$api.getdetails(usedata).then((res) => {
                    if(res.auditor == sessionStorage.getItem("jobNum")){
                        sessionStorage.setItem("ids",res.auditor);
                        this.detail = res
                        this.forReason = res.applyReason;
                    }else{
                        this.status=false;
                    }

                })
            }
        }
    };
</script>

<style scoped>
    .pos_item_left {
        height: 12px;
        font-size: 12px;
        font-family: Source Han Sans CN;
        font-weight: 400;
        color: rgba(147, 147, 147, 1);
        padding-left: 29px;
        width: 100px;
    }

    .forButtons {
        display: flex;
        justify-content: space-between;
        width: 375px;
        padding: 0 20px 0 26px;
    }

    .pos_item_right {
        width: 140px;
        height: 12px;
        font-size: 12px;
        font-family: Source Han Sans CN;
        font-weight: 500;
        color: rgba(65, 64, 64, 1);
        text-align: right;
    }

    .area_item_left {
        width: 58px;
        height: 12px;
        font-size: 12px;
        font-family: Source Han Sans CN;
        font-weight: 400;
        line-height: 20px;
        color: rgba(147, 147, 147, 1);
        margin-left: 28px;
    }

    .for_arrow {
        position: absolute;
        background: url("../assets/img/arrow.gif") no-repeat center;
        background-size: 100% auto;
        width: 15px;
        height: 25px;
        margin-left: 317px;
        margin-top: -21px;
    }

    .area_item_right {
        width: 60px;
        height: 12px;
        font-size: 12px;
        font-family: Source Han Sans CN;
        font-weight: 500;
        line-height: 20px;
        color: rgba(65, 64, 64, 1);
        margin-right: 40px;
        text-align: right;
    }

    .persion_item_left {
        width: 58px;
        height: 12px;
        font-size: 12px;
        font-family: Source Han Sans CN;
        font-weight: 400;
        line-height: 20px;
        color: rgba(147, 147, 147, 1);
        margin-left: 28px;
    }

    .persion_item_right {
        width: 95px;
        height: 12px;
        font-size: 12px;
        font-family: Source Han Sans CN;
        font-weight: 500;
        color: rgba(65, 64, 64, 1);
        float: right;
    }

    .for_img1 {
        background: url("../assets/img/examine_1.png") no-repeat center;
        background-size: 100% auto;
        margin-left: 28px;
        width: 19.57px;
        height: 18px;
    }

    .for_img2 {
        position: absolute;
        background: url("../assets/img/examine_2.png") no-repeat center;
        background-size: 100% auto;
        margin-left: 28px;
        margin-top: 20px;
        width: 19.57px;
        height: 18px;
    }

    .for_img3 {
        position: absolute;
        background: url("../assets/img/examine_3.png") no-repeat center;
        background-size: 100% auto;
        margin-left: 28px;
        margin-top: 20px;
        width: 19.57px;
        height: 18px;
    }

    .for_img4 {
        background: url("../assets/img/examine_4.png") no-repeat center;
        background-size: 100% auto;
        margin-left: 28px;
        width: 19.57px;
        height: 18px;
    }

    .for_img5 {
        background: url("../assets/img/examine_5.png") no-repeat center;
        background-size: 100% auto;
        margin-left: 28px;
        width: 19.57px;
        height: 18px;
        margin-top: 20px;
    }

    .for_img6 {
        position: absolute;
        background: url("../assets/img/examine_6.png") no-repeat center;
        background-size: 100% auto;
        margin-left: 28px;
        margin-top: 20px;
        width: 19.57px;
        height: 18px;
    }

    .content {
        background: #f2f4f5;
        height: 718px;
        width: 1366px;
        padding-top: 40px;
        padding-left: 83px;
    }

    .topPart {
        width: 375px;
        height: 166px;
        background: white;
        padding-top: 23px;
    }

    .bottomPart {
        margin-top: 29px;
        width: 375px;
        height: 117px;
        background: rgba(255, 255, 255, 1);
        padding-top: 23px;
    }

    .subButton {
        background: url("../assets/img/agreebutton.png") no-repeat center;
        width: 160px;
        height: 53px;
        margin-top: 16px;
        padding-top: 12px;
    }

    .rejButton {
        background: url("../assets/img/rejectbutton.png") no-repeat center;
        width: 160px;
        height: 53px;
        margin-top: 16px;
        padding-top: 12px;

    }

    ::-webkit-input-placeholder {
        color: #bbbbbb;
        font-size: 3px;
    }

    .subcontent {
        position: relative;
        width: 43px;
        height: 15px;
        font-size: 15px;
        font-family: Source Han Sans CN;
        font-weight: 400;
        line-height: 26px;
        color: rgba(255, 255, 255, 1);
        opacity: 1;
        align-items: center;
        margin-left: 63px;
    }

    .theLine1 {
        width: 317px;
        height: 0px;
        border: 1px solid rgba(230, 230, 230, 1);
        opacity: 1;
        margin-left: 30px;
        margin-top: 9px;
    }

    .theLine2 {
        width: 317px;
        height: 1px;
        background: rgba(230, 230, 230, 1);
        opacity: 1;
        margin-left: 30px;
        margin-top: 55px;
    }


    .font_area {
        width: 317px;
        height: 85px;
        background: rgba(243, 243, 243, 1);
        border: 1px solid rgba(210, 210, 210, 1);
        opacity: 1;
        border-radius: 6px;
        margin-top: 16px;
        margin-left: 23px;
    }

    .subButtona {
        width: 191px;
        height: 39px;
        background: rgba(218, 218, 218, 1);
        opacity: 1;
        border-radius: 20px;
        margin-left: 88px;
        text-align: center;
        margin-top: 16px;
        padding-top: 6px;
    }

    .subcontent2 {
        width: 45px;
        height: 15px;
        font-size: 15px;
        font-family: Source Han Sans CN;
        font-weight: 400;
        line-height: 26px;
        color: rgba(112, 112, 112, 1);

    }

    .position {
        display: flex;
        justify-content: space-between;
        height: 20px;
        flex-wrap: wrap;
        width: 315px;
    }

    .mainContent {
        width: 1200px;
        height: 623px;
        background: white;
        display: flex;
        justify-content: space-between;
        flex-wrap: wrap;
        padding-bottom: 117px;
    }

    .leftPart {
        width: 500px;
        height: 200px;
        margin-top: 148px;
        margin-left: 148px;
    }

    .rightPart {
        width: 500px;
        height: 200px;
        margin-top: 148px;
    }

    .forBut {
        width: 420px;
        height: 55px;
        margin-left: 390px;
        display: flex;
        justify-content: space-between;
    }
    .noRight{
        margin: 0 auto;
        font-size: 20px;
    }
</style>